package com.dlc.shop.sys.common.listener;

import com.dlc.shop.bean.event.GetShopSupperAdminEvent;
import com.dlc.shop.sys.common.model.ShopEmployee;
import com.dlc.shop.sys.common.service.ShopEmployeeService;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author gaozijie
 * @since 2023-12-14
 */
@Component
@AllArgsConstructor
public class GetShopSuperAdminListener {
    private final ShopEmployeeService shopEmployeeService;

    @EventListener(GetShopSupperAdminEvent.class)
    public void getShopSuperAdmin(GetShopSupperAdminEvent event) {
        if (Objects.isNull(event.getShopId())) {
            return;
        }
        ShopEmployee employee = shopEmployeeService.getMerchantInfoByShopId(event.getShopId());
        BeanUtils.copyProperties(employee, event);
    }
}
